﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    public class XBorderThicknessConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            string thicknessStr = valueNode.Attributes["Value"];
            if(!string.IsNullOrEmpty(thicknessStr))
            {
                ThicknessConverter tc = new ThicknessConverter();
                return tc.ConvertFromString(thicknessStr);
            }
            return null;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            Metadata.ValueNode vNode = new Metadata.ValueNode("Thickness");
            vNode.Attributes = new Dictionary<string, string>();
            ThicknessConverter tc = new ThicknessConverter();
            
            vNode.Attributes.Add("Value",tc.ConvertToString(value));

            return vNode;
        }
    }
}
